package com.lingxin.gps.wap;

import com.jfinal.config.*;
import com.jfinal.template.Engine;
import com.pisces.core.EnvEnum;
import com.pisces.core.route.AutoBindRoutes;

/**
 * 系统配置
 * 
 * @author David Chen
 *
 */
public class AppConfig extends JFinalConfig {

	/** 应用域名 */
	public static String APP_DOMAIN;

	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("app.cfg.properties");
		me.setDevMode(EnvEnum.dev == EnvEnum.valueOf(getProperty("env", "dev")));

		me.setError404View("/WEB-INF/views/common/error.html");
		me.setError500View("/WEB-INF/views/common/error.html");
		// 1G
		me.setMaxPostSize(1024 * 1024 * 1024);
		me.setEncoding("UTF-8");
		me.setBaseUploadPath(getProperty("uploadDirTmp"));

		APP_DOMAIN = getProperty("appDomain");
	}

	@Override
	public void configRoute(Routes routes) {
		routes.setBaseViewPath("/WEB-INF/views/");
		boolean dev = EnvEnum.dev == EnvEnum.valueOf(getProperty("env", "dev"));
		if (dev) {
			//routes.add("/dev", DevToolController.class);
		}

		AutoBindRoutes autoBindRoutes = new AutoBindRoutes();
		autoBindRoutes.autoScan(false);
		autoBindRoutes.setBaseViewPath("/WEB-INF/views/");
		//autoBindRoutes.addJars("lingxin-wap-1.0.0-SNAPSHOT.jar");
		routes.add(autoBindRoutes);
	}

	@Override
	public void configPlugin(Plugins me) {
		loadPropertyFile("service.properties");

		// 启动Druid主数据库连接池插件
//		DruidPlugin dp = new DruidPlugin(getProperty("master.jdbc.url"), getProperty("master.jdbc.username"), getProperty("master.jdbc.password"));
//		me.add(dp);
//		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
//		me.add(arp);
//		arp.addMapping("sys_account", Account.class);
//
//		// 启动Spring
//		me.add( new SpringPlugin("classpath:applicationContext.xml"));


		// 启动EhCache插件
		// plugins.add(new EhCachePlugin());
	}

	@Override
	public void configInterceptor(Interceptors me) {
		
	}

	@Override
	public void configHandler(Handlers handlers) {
		WapRedirectHandler redirectHandler = new WapRedirectHandler();
		handlers.add(redirectHandler);
	}

	@Override
	public void configEngine(Engine me) {

	}

}
